package com.xuetang9.fujian.threaddemo;

/**
 * @author: fujian
 * @description: 巩固对线程5个状态的理解
 * @date: 2021/5/2 16:06
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo
 **/
public class ThreadStatusDemo {
    public static void main(String[] args) {
        MyThread1 thread1 = new MyThread1("luff");
        System.out.println("thread.start前" + "新建状态");
        thread1.start();
        System.out.println("调用thread.start那一瞬间：" + "就绪状态");
    }
}

class MyThread1 extends Thread{

    public MyThread1(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println("线程：" + Thread.currentThread().getName() + "进入运行状态");
        for (int i = 0; i < 10; i++) {
            System.out.println(i);
            System.out.println("线程：" + Thread.currentThread().getName() + "进入阻塞状态");
            if (i == 5){
                Thread.currentThread().interrupt();
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                System.out.println("线程进入中断状态");
                e.printStackTrace();
            }
            System.out.println("线程结束阻塞状态进入运行状态");
        }
        System.out.println("线程进入停止状态");
    }
}